package org.springframework.beans.factory.exception;

import org.springframework.beans.FatalBeanException;
import org.springframework.lang.Nullable;

@SuppressWarnings("serial")
public class CannotLoadBeanClassException extends FatalBeanException {

	@Nullable
	private String resourceDescription;

	@Nullable
	private String beanName;

	@Nullable
	private String beanClassName;

	public CannotLoadBeanClassException(@Nullable String resourceDescription, String beanName, @Nullable String beanClassName, ClassNotFoundException cause) {
		super("Cannot find class [" + beanClassName + "] for bean with name '" + beanName + "'" + (resourceDescription != null ? " defined in " + resourceDescription : ""), cause);
		this.resourceDescription = resourceDescription;
		this.beanName = beanName;
		this.beanClassName = beanClassName;
	}

	public CannotLoadBeanClassException(@Nullable String resourceDescription, String beanName, @Nullable String beanClassName, LinkageError cause) {
		super("Error loading class [" + beanClassName + "] for bean with name '" + beanName + "'" + (resourceDescription != null ? " defined in " + resourceDescription : "") + ": problem with class file or dependent class", cause);
		this.resourceDescription = resourceDescription;
		this.beanName = beanName;
		this.beanClassName = beanClassName;
	}

	@Nullable
	public String getResourceDescription() {
		return this.resourceDescription;
	}

	@Nullable
	public String getBeanName() {
		return this.beanName;
	}

	@Nullable
	public String getBeanClassName() {
		return this.beanClassName;
	}
}
